﻿@typeparam TItem
@inherits _BaseDataGridModal<TItem>
<Modal Visible="@PopupVisible" Closed="@Cancel">
    <ModalBackdrop />
    <ModalContent>
        <ModalHeader>
            <ModalTitle>
                Row Edit
            </ModalTitle>
            <CloseButton Clicked="@Cancel" />
        </ModalHeader>
        <ModalBody>
            <Fields>
                @foreach ( var column in Columns )
                {
                    @if ( column.ColumnType == DataGridColumnType.Command )
                        continue;

                    @if ( column.Editable )
                    {
                        <Field ColumnSize="ColumnSize.IsHalf.OnDesktop" Padding="Blazorise.Padding.Is2.OnX.Is2.OnY">
                            <Field>
                                <FieldLabel>
                                    @column.Caption
                                </FieldLabel>
                                <FieldBody>
                                    <_DataGridCell TItem="TItem" Column="@column" Item="@EditItem" CellEditContext="@EditItemCellValues[column.ElementId]" />
                                </FieldBody>
                            </Field>
                        </Field>
                    }
                }
            </Fields>
        </ModalBody>
        <ModalFooter>
            @if ( ParentDataGrid?.CommandColumn?.SaveCommandAllowed == true )
            {
                @if ( ParentDataGrid?.CommandColumn?.SaveCommandTemplate != null )
                {
                    @ParentDataGrid.CommandColumn.SaveCommandTemplate( new CommandContext<TItem>
                    {
                        Clicked = Save,
                        Item = EditItem,
                    } )
                }
                else
                {
                    <Button Color="Color.Link" Clicked="@Save">Save</Button>
                }
            }
            @if ( ParentDataGrid?.CommandColumn?.CancelCommandAllowed == true )
            {
                @if ( ParentDataGrid?.CommandColumn?.CancelCommandTemplate != null )
                {
                    @ParentDataGrid.CommandColumn.CancelCommandTemplate( new CommandContext<TItem>
                    {
                        Clicked = Cancel,
                        Item = EditItem,
                    } )
                }
                else
                {
                    <Button Color="Color.Link" Clicked="@Cancel">Cancel</Button>
                }
            }
        </ModalFooter>
    </ModalContent>
</Modal>